package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.basic.ObjectUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.support.base.EventController;
import com.qire.common.widget.adapter.auto.AutoVariable;
import com.qire.manhua.BR;
import com.qire.manhua.activity.MessageCommentListActivity;
import com.qire.manhua.databinding.ActivityMessageCommentListBinding;
import com.qire.manhua.model.viewModel.impl.MessageCommentListViewModel;
import com.qire.manhua.model.viewModel.impl.MessageCommentListViewModel.MessageCommentItemViewModel;
import com.scwang.smart.refresh.layout.api.RefreshLayout;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

public class MessageCommentListController extends EventController<MessageCommentListActivity> implements AutoVariable {

    private MessageCommentListViewModel viewModel;

    public MessageCommentListController(@NonNull MessageCommentListActivity lifecycleOwner) {
        super(lifecycleOwner);
    }

    @Override
    protected void bindView() {
        ActivityMessageCommentListBinding viewDataBinder = owner.viewDataBinder();
        viewDataBinder.setMessageCommentListController(this);
    }

    @Override
    public void bindVariable(ViewDataBinding viewBind) {
        viewBind.setVariable(BR.messageCommentListController, this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(MessageCommentListViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void refreshLayoutOnLoadMore(RefreshLayout refreshLayout) {
        viewModel.loadMoreData();
    }

    public void refreshLayoutOnRefresh(RefreshLayout refreshLayout) {
        viewModel.loadData();
    }

    public void backBtnOnClick(View view) {
        owner.onBackPressed();
    }

    public void messageCommentItemOnClick(View view) {
        MessageCommentItemViewModel itemViewModel = ObjectUtil.as(view.getTag(), MessageCommentItemViewModel.class);
        if(ObjectUtil.nonNull(itemViewModel)) {
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.MessageCommentDetailPage)
                    .withData("commentId", itemViewModel.id)
                    .navigation();
        }
    }

    public void messageCommentItemGoComicOnClick(View view) {
        MessageCommentItemViewModel itemViewModel = ObjectUtil.as(view.getTag(), MessageCommentItemViewModel.class);
        if(ObjectUtil.nonNull(itemViewModel)) {
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicDetailPage)
                    .withData("comicBookId", itemViewModel.comicId)
                    .navigation();
        }
    }

}
